using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ConsolePlayer
{


	public partial class PlayWindow : Form
	{
		public event EventHandler<KeyEventArgs> KeyPressEvent;
		public event EventHandler<SizeEventArgs> SizeEvent;
		public PlayWindow()
		{
			InitializeComponent();
			Screen s = Screen.PrimaryScreen;
			int width = s.Bounds.Width;
			int height = s.Bounds.Height;
			this.Location = new Point(width / 4, height / 4);
			this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
			this.panelWnd.BackColor = Color.Black;
		}

		private void PlayWindow_SizeChanged(object sender, EventArgs e)
		{
			if( SizeEvent != null )
			{
				SizeEventArgs args = new SizeEventArgs(new Rectangle(panelWnd.Left, panelWnd.Top, panelWnd.Width, panelWnd.Height));
				SizeEvent(this, args);
			}
		}

		private void PlayWindow_FormClosed(object sender, FormClosedEventArgs e)
		{

		}
		private void PlayWindow_KeyPress(object sender, KeyPressEventArgs e)
		{
			Keys key = (Keys)0xffff;
			if ( e.KeyChar == 'f' || e.KeyChar == 'F' )
			{
				key = Keys.F;
				//full screen
			} 
			else if( e.KeyChar == 'a' || e.KeyChar == 'A' )
			{
				key = Keys.A;
			}
			else if (e.KeyChar == 'd' || e.KeyChar == 'D')
			{
				key = Keys.D;
			}
			else if (e.KeyChar == 'w' || e.KeyChar == 'W')
			{
				key = Keys.W;
			}
			else if (e.KeyChar == 's' || e.KeyChar == 'S')
			{
				key = Keys.S;
			}
			else if (e.KeyChar == 'p' || e.KeyChar == 'P' )
			{
				key = Keys.P;
				
			}
			else if( e.KeyChar == 'n' || e.KeyChar == 'N' )
			{
				key = Keys.N;
			}
			else if( e.KeyChar == 'b' || e.KeyChar == 'B' )
			{
				key = Keys.B;
			}
			else if( e.KeyChar == 'c' || e.KeyChar == 'C' )
			{
				key = Keys.C;
			}
			else if( e.KeyChar == 'q' || e.KeyChar == 'Q' )
			{
				this.Close();
			}
			

			if( KeyPressEvent != null )
			{
				KeyEventArgs args = new KeyEventArgs((char)key);
				KeyPressEvent(this, args);
			}
		}

		public Rectangle PlayWndRect
		{
			get
			{
				return new Rectangle(panelWnd.Left, panelWnd.Top, panelWnd.Width, panelWnd.Height);
			}
		}

		public IntPtr PlayWnd
		{
		    get { return panelWnd.Handle; }
		}
	}

	public class KeyEventArgs : EventArgs
	{
		private char _key;
		public KeyEventArgs(char key)
		{
			_key = key;
		}

		public Keys Key
		{
			get { return (Keys)_key; }
		}
	}

	public class SizeEventArgs : EventArgs
	{
		private Rectangle _size;
		public SizeEventArgs(Rectangle size)
		{
			_size = size;
		}

		public Rectangle Size
		{
			get { return _size; }
		}
	}

}